#!/bin/bash

gappath=`pwd`/..

if [ `uname -m` = x86_64 ]; then
  GMPLIBX=Gmplib64
else
  GMPLIBX=Gmplib
fi

mkdir -p $gappath/local/pkg/CaratStandalone
rm -rf $gappath/local/pkg/CaratStandalone
mkdir -p $gappath/local/pkg/CaratStandalone
cd $gappath/local/pkg/CaratStandalone
tar xzpf ../../../pkg/carat/carat-2.1b1.tgz
cd carat-2.1b1
# doesn't work on some installation any more, so just compile included gmp
# as well
##  cp ../../../../pkg/$GMPLIBX/lib/* lib
##  cp ../../../../pkg/$GMPLIBX/include/* include
##  mv Makefile Makefile.orig
##  grep -v "Gmp\\\\" Makefile.orig > Makefile
make TOPDIR=`pwd` CC=gcc CFLAGS="-O2 -static" 

# bad hack
cd bin
ln -s *cc i686-pc-linux-gnu-gcc-default32
ln -s *cc x86_64-unknown-linux-gnu-gcc-default64

cd ../../../../pkg/carat
rm -f bin
ln -s ../../local/pkg/CaratStandalone/carat-2.1b1/bin bin


